<template>
  <div>
    <h1>WebSocket Example</h1>
    <ul>
      <li v-for="message in messages" :key="message.id">{{ message.text }}</li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ws: null,
      messages: []
    };
  },
  created() {
    this.ws = new WebSocket('ws://192.168.71.116:8666/websocket/1');
    this.ws.onopen = () => {
      console.log('WebSocket connected');
    };
    this.ws.onmessage = (event) => {
      // const message = JSON.parse(event.data);
      // this.messages.push(message);
      console.log(event.data);
    };
    this.ws.onclose = () => {
      console.log('WebSocket closed');
    };
  },
  beforeDestroy() {
    this.ws.close();
  }
};
</script>